package com.qh.resourcehub.info.virtualresource.controller;


import com.qh.resourcehub.info.entity.ApplicationData;
import com.qh.resourcehub.info.virtualresource.service.VmApplicationService;
import com.qh.resourcehub.utils.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * IP 申请用户资源管理
 */
@RestController
@RequestMapping("/VmApplication")
public class VmApplicationController {

    @Autowired
    VmApplicationService vmApplicationServicel;

    /**
     * 用户信息高级查询当前填写的以及申请的信息  主任审核
     */
    @GetMapping("/queryVmDataService")
    public ApiResponse queryVmDataService(@RequestBody ApplicationData applicationData) {
        try {
            List<Map<String,Object>> i = vmApplicationServicel.queryVmDataService(applicationData);
            if (i.size()>0){
               return ApiResponse.succeed(i);
            }else {
                return ApiResponse.succeedNoData();
            }
        }catch (Exception e){
            return ApiResponse.succeedRequestNo();
        }
    }




    /**
     * IP申请新增
     * @param applicationData
     * @return
     */
    @PostMapping("/ApplicationSave")
    public ApiResponse ApplicationSave(@RequestBody ApplicationData applicationData) {
        System.out.println(applicationData);
        try {
            int i = vmApplicationServicel.ApplicationSave(applicationData);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            return ApiResponse.succeedRequestNo();
        }
    }
    /**
     * IP申请修改
     * @param applicationData
     * @return
     */
    @PostMapping("/ApplicationUpdataById")
    public ApiResponse ApplicationUpdataById(@RequestBody ApplicationData applicationData) {
        System.out.println(applicationData);
        try {
            int i = vmApplicationServicel.ApplicationUpdataById(applicationData);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            return ApiResponse.succeedRequestNo();
        }
    }
    /**
     * IP申请删除
     * @param applicationData
     * @return
     */
    @PostMapping("/ApplicationDelById")
    public ApiResponse ApplicationDelById(@RequestBody ApplicationData applicationData) {
        System.out.println(applicationData);
        try {
            int i = vmApplicationServicel.ApplicationDelById(applicationData);
            if (i>0){
                return ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            return ApiResponse.succeedRequestNo();
        }
    }
    /**
     * IP申请提交
     * @param applicationData
     * @return
     */
    @PostMapping("/VMApplicationSubmit")
    public ApiResponse IPApplicationSubmit(@RequestBody ApplicationData applicationData) {
        try {
            int i = vmApplicationServicel.VMApplicationSubmit(applicationData);
            if (i>0){
              return   ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            return ApiResponse.succeedRequestNo();
        }
    }

    /**
     * IP申请撤回
     * @param applicationData
     * @return
     */
    @PostMapping("/VMApplicationWithdraw")
    public ApiResponse IPApplicationWithdraw(@RequestBody ApplicationData applicationData) {
        try {
            int i = vmApplicationServicel.VMApplicationWithdraw(applicationData);
            if (i>0){
              return   ApiResponse.succeedRequest();
            }else {
                return ApiResponse.succeedRequestNo();
            }
        }catch (Exception e){
            return ApiResponse.succeedRequestNo();
        }
    }
}
